package src.main.BehavioralPatterns.Observer;

// 具体观察者：气象统计显示屏
public class StatisticsDisplay implements Observer {
    private float maxTemperature = -100; // 跟踪最高温度
    private float minTemperature = 100; // 跟踪最低温度
    private float sumTemperature; // 温度总和
    private int numReadings; // 数据读取次数

    @Override
    public void update(float temperature, float humidity, float pressure) {
        // 更新统计信息
        sumTemperature += temperature;
        numReadings++;

        // 更新最高/最低温度记录
        if (temperature > maxTemperature) {
            maxTemperature = temperature;
        }
        if (temperature < minTemperature) {
            minTemperature = temperature;
        }
        display();
    }

    public void display() {
        System.out.printf("[气象统计] 平均 %.1f°C | 最高 %.1f°C | 最低 %.1f°C\n",
                (sumTemperature / numReadings), maxTemperature, minTemperature);
    }
}
